package health_system.health_system.websocket;

import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import jakarta.servlet.annotation.WebListener;
import jakarta.websocket.CloseReason;

import java.io.IOException;

@WebListener
public class WebSocketShutdownListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {}

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
//        DataWebSocketServer.getUserSessions().forEach((username, session) -> {
//            if (session.isOpen()) {
//                try {
//                    session.close(new CloseReason(CloseReason.CloseCodes.GOING_AWAY, "服务器关闭"));
//                } catch (IOException e) {
//                    System.err.println("关闭会话异常: " + e.getMessage());
//                }
//            }
//        });
//        DataWebSocketServer.clearUserSessions();
    }
}